package com.fenghongzhang.day006;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;
import java.util.Map;

public class VPAdapter extends PagerAdapter {

    private Context context;
    private List<Food> list;


    public VPAdapter(Context context, List<Food> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
//        super.destroyItem(container, position, object);
        container.removeView((View)object);
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {

        //1,加载布局
        View inflate = LayoutInflater.from(context).inflate(R.layout.vp_layout, null);

        TextView textView = inflate.findViewById(R.id.vp_text);



        //重要
        container.addView(inflate);

        return inflate;
    }
}
